class UI

def UI.get_gui_input
   include_class 'javax.swing.JFileChooser'

   chooser = JFileChooser.new  # starts at home directory by default
   chooser.set_file_selection_mode(JFileChooser::DIRECTORIES_ONLY)
   return_val = chooser.show_open_dialog(javax.swing.JPanel.new)

   if return_val == JFileChooser::APPROVE_OPTION
     ARGV[0] = chooser.get_selected_file.get_path
   end
end

# TODO: Need to add a test for the command-line version of getting the table of groups of files
# TODO: Currently, the button is writing over the table output--needs to be updated ASAP.
# An example of getting a window opened that will ultimately be used for displaying output
def UI.set_gui_output(groups_of_files)
   include_class 'javax.swing.JFrame'
   include_class 'javax.swing.JLabel'
   include_class 'javax.swing.JButton'
   include_class 'java.awt.event.ActionEvent'
   include_class 'java.lang.System'

   frame = JFrame.new("Output for Dup Detector")

   os_name = System.get_property("os.name")
   file_open_cmd = ""
   if os_name =~ /Mac/
     puts "I am on a Mac"
     file_open_cmd = "open"
   elsif os_name =~ /Window/
     puts "I am on Windows"
     file_open_cmd = "cmd.exe /c start"
   elsif os_name =~ /Linux/
     puts "I am on Linux--not currently supported"
     puts "cat"
   else
     puts "I don't know my operating system"
     file_open_cmd = "echo"
   end

   output = "<html><table>"
   groups_of_files.table_elements do | struct |
     output += "<tr><td>#{struct.groupnum}</td><td>#{struct.path}</td></tr>"
### TODO: associate this code with an action from the user via the GUI output
### to open a selected file.
#     system("#{file_open_cmd} #{struct.path}")
     
   end
   output << "</table></html>"
#   label = JLabel.new(output)
#   frame.getContentPane().add(label)

#   frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
#   b1 = JButton.new("Click me")
#   b1.add_action_listener(OurActionListener.new)
#   frame.getContentPane().add(b1)

   frame.pack()
   frame.setVisible(true)
end
include_class 'java.awt.event.ActionListener'

class OurActionListener
  include java.awt.event.ActionListener
  def actionPerformed(event)
    puts "you clicked the button"
  end

end

end